package arena;

import com.jme.image.Texture;
import com.jme.image.Texture.WrapMode;
import com.jme.math.Line;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Icosahedron;
import com.jme.scene.state.BlendState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jmex.effects.particles.ParticleFactory;
import com.jmex.effects.particles.ParticleSystem;
import com.jmex.effects.particles.SimpleParticleInfluenceFactory;

public class Bonus_Node extends Node {
	private static final long serialVersionUID = 1L;
	private ParticleSystem particles;
	private Icosahedron model;

	public Bonus_Node(DisplaySystem display)
	{
		model=new Icosahedron("bonus", 1f);
		Texture tex = TextureManager.loadTexture(
		  			  		"src/objects/tex/Tile_183.jpg",
		  			  		Texture.MinificationFilter.Trilinear,
		  			  		Texture.MagnificationFilter.Bilinear);
		tex.setScale(new Vector3f(2, 2, 2));
		tex.setWrap(WrapMode.BorderClamp);

		TextureState ts_floor = display.getRenderer().createTextureState();
		ts_floor.setEnabled(true);
		ts_floor.setTexture(tex);
		model.setRenderState(ts_floor);
		model.setLocalTranslation(0, 0.5f, 0);

	    particles = ParticleFactory.buildParticles("particles", 50);
	    particles.setEmissionDirection(new Vector3f(0, 1, 0));
	    particles.setStartSize(1.7f);
	    particles.setEndSize(1.5f);
	    particles.setOriginOffset(new Vector3f(0, -2, 0));
	    particles.setInitialVelocity(  0.15f);
	    particles.setMinimumLifeTime( 50f);
	    particles.setMaximumLifeTime(200f);
	    particles.setStartColor(new ColorRGBA(ColorRGBA.cyan));
	    particles.setMaximumAngle(0.3f);
	    particles.addInfluence(SimpleParticleInfluenceFactory.createBasicVortex(0.1f, 0.2f, new Line(new Vector3f(0, 0, 0), new Vector3f(0, 1, 0)), false, true));
	    particles.addInfluence(SimpleParticleInfluenceFactory.createBasicGravity(new Vector3f(0, -1.5f, 0), true));
	        
        BlendState as1 = display.getRenderer().createBlendState();
        as1.setBlendEnabled(true);
        as1.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
        as1.setDestinationFunction(BlendState.DestinationFunction.One);
        as1.setTestEnabled(true);
        as1.setTestFunction(BlendState.TestFunction.GreaterThan);
        as1.setEnabled(true);
        particles.setRenderState(as1);
			
        Texture ts=TextureManager.loadTexture(
	            Bonus_Node.class.getClassLoader().getResource(
	            "textures/sparkle.png"),
	            Texture.MinificationFilter.Trilinear,
	            Texture.MagnificationFilter.Bilinear);
        TextureState tex_state = display.getRenderer().createTextureState();
        tex_state.setEnabled(true);
	  	tex_state.setTexture(ts);
	        
	    particles.setRenderState(tex_state);
	    this.attachChild(particles);
	    this.attachChild(model);	
	}
}
